﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chowpoo.Diagnose;
using CourseSystem.Common.Chat;
using log4net;

namespace CourseSystem.Stat
{
    public class StatThread : ThreadDiagnosable
    {
        private static readonly ILog Log = LogManager.GetLogger(typeof(StatThread));

        public StatThread(TimeSpan relaxTimeout, TimeSpan dozeTimeout)
            : base(relaxTimeout, dozeTimeout)
        {
        }

        protected override bool RelaxAfterExecution()
        {
            try
            {
                //清理无活跃用户
                UserOnlineStat.ClearOnline();
                //更新到数据库
                IpStat.UpdateStat();

                //清理聊天人数
                ChatHelper.ClearUnOnline();
                return true;
            }
            catch (Exception ex)
            {
                Log.Error("统计线程遇到异常!!", ex);
                return false;
            }
        }
    }
}
